package com.efast.dmom.mes.controller;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.Part;
import com.efast.dmom.mes.bean.PartAlternate;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.PartAlternateService;

@Controller
@RequestMapping("/partAlternate")
public class PartAlternateController {
	@Autowired
	private PartAlternateService partAlternateService;
	
	@RequestMapping(value = "/operateToPartAlternate")
	public @ResponseBody ResultBean operateToBasicByPartAlternate(@RequestBody PartAlternate  partAlternate) {
		if (partAlternate.getModificationFlag() == IModificationFlags.NEW) {
			return partAlternateService.save(partAlternate);
			// Judge update
		} else if (partAlternate.getModificationFlag() == IModificationFlags.MODIFIED) {
			return partAlternateService.update(partAlternate);
			// Judge to delete
		} else if (partAlternate.getModificationFlag() == IModificationFlags.DELETED) {
			return partAlternateService.delete(partAlternate);
		}
		return null;
	}
	
	@RequestMapping(value = "/operateToListPartAlternate")
	public @ResponseBody ResultBean operateToBasicByListPartAlternate(int type,@RequestBody PartAlternate  partAlternate) {
		if (partAlternate.getModificationFlag() == IModificationFlags.NEW) {
			return partAlternateService.save(partAlternate);
			// Judge update
		} else if (partAlternate.getModificationFlag() == IModificationFlags.MODIFIED) {
			return partAlternateService.update(partAlternate);
			// Judge to delete
		} else if (partAlternate.getModificationFlag() == IModificationFlags.DELETED) {
			return partAlternateService.delete(partAlternate);
		}
		return null;
	}
	@RequestMapping(value = "/getById")
	public  @ResponseBody PartAlternate getById(long id) {
		return partAlternateService.getById(id);
	}
	@RequestMapping(value = "/getByPartId")
	public  @ResponseBody List<PartAlternate> getByPartId(long id){
		return partAlternateService.getByPartId(id);
	}
	@RequestMapping(value = "/getByAlternatePartId")
	public  @ResponseBody List<PartAlternate> getByAlternatePartId(long id){
		return partAlternateService.getByAlternatePartId(id);
	}
	@RequestMapping(value = "/getAlternatePartByPartId")
	public  @ResponseBody List<Part> getAlternatePartByPartId(long id){
		return partAlternateService.getAlternatePartByPartId(id);
	}
	@RequestMapping(value = "/getPartByAlternatePartId")
	public  @ResponseBody List<Part> getPartByAlternatePartId(long id){
		return partAlternateService.getPartByAlternatePartId(id);
	}
	
	
}
